package c.a.a.z.b;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.DashPathEffect;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.RectF;
import c.a.a.b0.e;
import c.a.a.b0.j.d;
import c.a.a.e0.f;
import c.a.a.e0.g;
import c.a.a.l;
import c.a.a.q;
import c.a.a.z.c.c;
import c.a.a.z.c.p;
import com.pgl.sys.ces.out.ISdkLite;
import java.util.ArrayList;
import java.util.List;

/* compiled from: BaseStrokeContent */
public abstract class a implements c.a.a.z.c.a.b, k, e {
    public final PathMeasure a = new PathMeasure();
    public final Path b = new Path();
    public final Path c = new Path();
    public final RectF d = new RectF();
    public final l e;
    public final c.a.a.b0.l.b f;
    public final List<b> g = new ArrayList();
    public final float[] h;
    public final Paint i;
    public final c.a.a.z.c.a<?, Float> j;
    public final c.a.a.z.c.a<?, Integer> k;
    public final List<c.a.a.z.c.a<?, Float>> l;
    public final c.a.a.z.c.a<?, Float> m;
    public c.a.a.z.c.a<ColorFilter, ColorFilter> n;

    /* compiled from: BaseStrokeContent */
    public static final class b {
        public final List<m> a = new ArrayList();
        public final s b;

        public b(s sVar, a aVar) {
            this.b = sVar;
        }
    }

    public a(l lVar, c.a.a.b0.l.b bVar, Cap cap, Join join, float f, d dVar, c.a.a.b0.j.b bVar2, List<c.a.a.b0.j.b> list, c.a.a.b0.j.b bVar3) {
        int i;
        c.a.a.z.a aVar = new c.a.a.z.a(1);
        this.i = aVar;
        this.e = lVar;
        this.f = bVar;
        aVar.setStyle(Style.STROKE);
        aVar.setStrokeCap(cap);
        aVar.setStrokeJoin(join);
        aVar.setStrokeMiter(f);
        this.k = dVar.a();
        this.j = bVar2.a();
        if (bVar3 == null) {
            this.m = null;
        } else {
            this.m = bVar3.a();
        }
        this.l = new ArrayList(list.size());
        this.h = new float[list.size()];
        for (i = 0; i < list.size(); i++) {
            this.l.add(((c.a.a.b0.j.b) list.get(i)).a());
        }
        bVar.e(this.k);
        bVar.e(this.j);
        for (i = 0; i < this.l.size(); i++) {
            bVar.e((c.a.a.z.c.a) this.l.get(i));
        }
        c.a.a.z.c.a aVar2 = this.m;
        if (aVar2 != null) {
            bVar.e(aVar2);
        }
        this.k.a.add(this);
        this.j.a.add(this);
        for (int i2 = 0; i2 < list.size(); i2++) {
            ((c.a.a.z.c.a) this.l.get(i2)).a.add(this);
        }
        c.a.a.z.c.a aVar3 = this.m;
        if (aVar3 != null) {
            aVar3.a.add(this);
        }
    }

    public void b(RectF rectF, Matrix matrix, boolean z) {
        this.b.reset();
        for (int i = 0; i < this.g.size(); i++) {
            b bVar = (b) this.g.get(i);
            for (int i2 = 0; i2 < bVar.a.size(); i2++) {
                this.b.addPath(((m) bVar.a.get(i2)).h(), matrix);
            }
        }
        this.b.computeBounds(this.d, false);
        float j = ((c) this.j).j();
        RectF rectF2 = this.d;
        j /= 2.0f;
        rectF2.set(rectF2.left - j, rectF2.top - j, rectF2.right + j, rectF2.bottom + j);
        rectF.set(this.d);
        rectF.set(rectF.left - 1.0f, rectF.top - 1.0f, rectF.right + 1.0f, rectF.bottom + 1.0f);
        c.a.a.c.a("StrokeContent#getBounds");
    }

    public void c() {
        this.e.invalidateSelf();
    }

    public void d(List<c> list, List<c> list2) {
        c cVar;
        c.a.a.b0.k.q.a aVar = c.a.a.b0.k.q.a.INDIVIDUALLY;
        s sVar = null;
        for (int size = list.size() - 1; size >= 0; size--) {
            cVar = (c) list.get(size);
            if (cVar instanceof s) {
                s sVar2 = (s) cVar;
                if (sVar2.c == aVar) {
                    sVar = sVar2;
                }
            }
        }
        if (sVar != null) {
            sVar.b.add(this);
        }
        b bVar = null;
        for (int size2 = list2.size() - 1; size2 >= 0; size2--) {
            cVar = (c) list2.get(size2);
            if (cVar instanceof s) {
                s sVar3 = (s) cVar;
                if (sVar3.c == aVar) {
                    if (bVar != null) {
                        this.g.add(bVar);
                    }
                    bVar = new b(sVar3, null);
                    sVar3.b.add(this);
                }
            }
            if (cVar instanceof m) {
                if (bVar == null) {
                    bVar = new b(sVar, null);
                }
                bVar.a.add((m) cVar);
            }
        }
        if (bVar != null) {
            this.g.add(bVar);
        }
    }

    public void f(e eVar, int i, List<e> list, e eVar2) {
        f.f(eVar, i, list, eVar2, this);
    }

    public void g(Canvas canvas, Matrix matrix, int i) {
        Canvas canvas2 = canvas;
        Matrix matrix2 = matrix;
        float[] fArr = (float[]) g.d.get();
        boolean z = false;
        fArr[0] = 0.0f;
        fArr[1] = 0.0f;
        fArr[2] = 37394.73f;
        fArr[3] = 39575.234f;
        matrix2.mapPoints(fArr);
        Object obj = (fArr[0] == fArr[2] || fArr[1] == fArr[3]) ? 1 : null;
        String str = "StrokeContent#draw";
        if (obj != null) {
            c.a.a.c.a(str);
            return;
        }
        c.a.a.z.c.e eVar = (c.a.a.z.c.e) this.k;
        float j = (((float) i) / 255.0f) * ((float) eVar.j(eVar.a(), eVar.c()));
        float f = 100.0f;
        this.i.setAlpha(f.c((int) ((j / 100.0f) * 255.0f), 0, ISdkLite.REGION_UNSET));
        this.i.setStrokeWidth(g.d(matrix) * ((c) this.j).j());
        if (this.i.getStrokeWidth() <= 0.0f) {
            c.a.a.c.a(str);
            return;
        }
        int i2;
        String str2 = "StrokeContent#applyDashPattern";
        float f2 = 1.0f;
        if (this.l.isEmpty()) {
            c.a.a.c.a(str2);
        } else {
            j = g.d(matrix);
            for (i2 = 0; i2 < this.l.size(); i2++) {
                float[] fArr2;
                this.h[i2] = ((Float) ((c.a.a.z.c.a) this.l.get(i2)).e()).floatValue();
                if (i2 % 2 == 0) {
                    fArr2 = this.h;
                    if (fArr2[i2] < 1.0f) {
                        fArr2[i2] = 1.0f;
                    }
                } else {
                    fArr2 = this.h;
                    if (fArr2[i2] < 0.1f) {
                        fArr2[i2] = 0.1f;
                    }
                }
                fArr2 = this.h;
                fArr2[i2] = fArr2[i2] * j;
            }
            c.a.a.z.c.a aVar = this.m;
            this.i.setPathEffect(new DashPathEffect(this.h, aVar == null ? 0.0f : ((Float) aVar.e()).floatValue() * j));
            c.a.a.c.a(str2);
        }
        c.a.a.z.c.a aVar2 = this.n;
        if (aVar2 != null) {
            this.i.setColorFilter((ColorFilter) aVar2.e());
        }
        int i3 = 0;
        while (i3 < this.g.size()) {
            b bVar = (b) this.g.get(i3);
            s sVar = bVar.b;
            if (sVar != null) {
                String str3 = "StrokeContent#applyTrimPath";
                if (sVar == null) {
                    c.a.a.c.a(str3);
                } else {
                    this.b.reset();
                    i2 = bVar.a.size();
                    while (true) {
                        i2--;
                        if (i2 < 0) {
                            break;
                        }
                        this.b.addPath(((m) bVar.a.get(i2)).h(), matrix2);
                    }
                    this.a.setPath(this.b, z);
                    float length = this.a.getLength();
                    while (this.a.nextContour()) {
                        length += this.a.getLength();
                    }
                    float floatValue = (((Float) bVar.b.f.e()).floatValue() * length) / 360.0f;
                    float floatValue2 = ((((Float) bVar.b.d.e()).floatValue() * length) / f) + floatValue;
                    float floatValue3 = ((((Float) bVar.b.e.e()).floatValue() * length) / f) + floatValue;
                    int size = bVar.a.size() - 1;
                    float f3 = 0.0f;
                    while (size >= 0) {
                        this.c.set(((m) bVar.a.get(size)).h());
                        this.c.transform(matrix2);
                        this.a.setPath(this.c, z);
                        float length2 = this.a.getLength();
                        if (floatValue3 > length) {
                            f = floatValue3 - length;
                            if (f < f3 + length2 && f3 < f) {
                                g.a(this.c, floatValue2 > length ? (floatValue2 - length) / length2 : 0.0f, Math.min(f / length2, f2), 0.0f);
                                canvas2.drawPath(this.c, this.i);
                                f3 += length2;
                                size--;
                                z = false;
                                f2 = 1.0f;
                            }
                        }
                        float f4 = f3 + length2;
                        if (f4 >= floatValue2 && f3 <= floatValue3) {
                            if (f4 > floatValue3 || floatValue2 >= f3) {
                                g.a(this.c, floatValue2 < f3 ? 0.0f : (floatValue2 - f3) / length2, floatValue3 > f4 ? 1.0f : (floatValue3 - f3) / length2, 0.0f);
                                canvas2.drawPath(this.c, this.i);
                            } else {
                                canvas2.drawPath(this.c, this.i);
                            }
                        }
                        f3 += length2;
                        size--;
                        z = false;
                        f2 = 1.0f;
                    }
                    c.a.a.c.a(str3);
                }
            } else {
                this.b.reset();
                for (int size2 = bVar.a.size() - 1; size2 >= 0; size2--) {
                    this.b.addPath(((m) bVar.a.get(size2)).h(), matrix2);
                }
                c.a.a.c.a("StrokeContent#buildPath");
                canvas2.drawPath(this.b, this.i);
                c.a.a.c.a("StrokeContent#drawPath");
            }
            i3++;
            z = false;
            f = 100.0f;
            f2 = 1.0f;
        }
        c.a.a.c.a(str);
    }

    public <T> void i(T t, c.a.a.f0.c<T> cVar) {
        c.a.a.z.c.a aVar;
        c.a.a.f0.c cVar2;
        if (t == q.d) {
            aVar = this.k;
            cVar2 = aVar.e;
            aVar.e = cVar;
        } else if (t == q.o) {
            aVar = this.j;
            cVar2 = aVar.e;
            aVar.e = cVar;
        } else if (t == q.C) {
            aVar = this.n;
            if (aVar != null) {
                this.f.u.remove(aVar);
            }
            if (cVar == null) {
                this.n = null;
                return;
            }
            p pVar = new p(cVar, null);
            this.n = pVar;
            pVar.a.add(this);
            this.f.e(this.n);
        }
    }
}
